﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ToWaDBFirst.Models;

namespace ToWaDBFirst.Controllers
{
    /**
     * Controller for the Inbox managing overview of all messages and view a specific message.
     **/
    [Authorize]
    public class InboxController : Controller
    {

        /**
         * Class objects to handle database and service operations.
         **/
        ToWaDBFirstDBEntities2 db = new ToWaDBFirstDBEntities2();
        ToWaService service = new ToWaService();
        
        /**
         * Method to handle requests to the Index View.
         * Returns to the index page.
         **/
        // GET: /Indbox/
        public ActionResult Index()
        {
            return View(service.GetInbox(User.Identity.Name));
        }

        /**
         * Method to handle requests to the details view to inspect a message.
         * Returns to the detail view of the message.
         **/
        // GET: /Indbox/Details/
        public ActionResult Details(int id)
        {
            MessageWrapper mw = service.InspectMessage(id);
            service.SetReadStatus(1, id, User.Identity.Name);
            return View(mw);
        }

        /**
         * Method to delete a specified message. Sending a request to the service to delete the message
         * with the specified messageId.
         * Returns to the index page of the Inbox.
         **/
        // GET: /Indbox/Delete/
        public ActionResult Delete(int id)
        {
            service.DeleteMessage(id, User.Identity.Name);
            return RedirectToAction("Index");
        }
    }
}
